package com.hyz.service.impl;

import client.AssetClient;
import com.hyz.pojo.request.ApprovalResultRequest;
import com.hyz.pojo.response.AssetSecondmentResponse;
import com.hyz.service.InformationService;
import com.hyz.util.AssetSecondmentUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.ResponseResult;
import pojo.asset.assetSecondment.AssetSecondment;
import pojo.asset.assetSecondment.AssetSecondmentResult;

import java.util.List;

/**
 * @author HGD
 * @date 2022/10/9 19:20
 */
@Service
public class InformationServiceImpl implements InformationService {

    @Autowired
    private AssetClient assetClient;
    @Autowired
    private AssetSecondmentUtils asUtils;

    @Override
    public ResponseResult<List<AssetSecondmentResponse>> ifGetAssetSecondments() {
        ResponseResult<List<AssetSecondment>> result = assetClient.ifGetAssetSecondments();
        return asUtils.getAssetSecondmentResponse(result);
    }

    @Override
    public ResponseResult<List<AssetSecondmentResponse>> ifUpdateAssetSecondment(ApprovalResultRequest request) {
        ResponseResult<String> result = assetClient.ifUpdateAssetSecondment(request.getApprovalId(),
                request.getResult() ? AssetSecondmentResult.INFORMATION_AGREE : AssetSecondmentResult.FAILED);
        int code = 200;
        if (result.getStatus() != code) {
            return new ResponseResult<>(result.getStatus(), result.getMsg());
        }
        return ifGetAssetSecondments();
    }
}
